#include <stdlib.h>
#include "fs.h"
#include "fmt_prt.h"

static struct linked_list fs_obj_list;

int32_t register_fs_obj(struct fs_obj_struct* fs_obj)
{
    if(!fs_obj) {
        //
        fmt_printf("register fs obj failed, fs_obj == NULL\n");
        return -1;
    }

    list_push(&fs_obj_list, &fs_obj->node);
    fmt_printf("register fs obj success, type == 0x%x\n", fs_obj->type);
}

struct fs_obj_struct* create_fs_obj()
{
    struct fs_obj_struct* fs_obj;

    fs_obj = malloc(sizeof(struct fs_obj_struct));
    if(!fs_obj) {
        //
        fmt_printf("create fs obj failed, malloc failed\n");
        return NULL;
    }
    return fs_obj;
}

struct fs_obj_struct* find_fs_obj(enum fs_type_enum type)
{
    struct linked_node* each_node;
    struct fs_obj_struct* fs_obj;

    list_for_each(each_node, &fs_obj_list) {
        fs_obj = container_of(each_node, struct fs_obj_struct, node);
        if(fs_obj->type == type) return fs_obj;
    }
    return NULL;
}

void free_fs_objs()
{
    
}